/* 对 axios 进行二次封装 */
import axios from 'axios'
import { Toast } from 'vant';

// 1. 创建一个axios 实例
let instance = axios.create({
	timeout: 10000,
	headers: {
		Accept: 'application/json, text/plain, */*',
		'Accept-Encoding': 'gzip, deflate, br',
		'Accept-Language': 'zh-CN,zh;q=0.9',
		appId: "",
		appKey: "",
		'Cache-Control': 'no-cache',
		Connection: 'keep-alive',
		constToken: 'kabtnOdd1b1AB0BVQUeEAcv3i/KPYTw+@bj',
		Cookie: 'i18n_redirected=zh_CN; source_type=504; s_channel=h5_web; is_login=false; utm_source=direct; utm_medium=direct; utm_campaign=direct; utm_term=direct; uc=direct; ut=direct; sajssdk_2015_cross_new_user=1; _ga_nefid_=7LsWTYUJjv1FQxQVFUbFQIr0WZQng5%2BN; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22180bc283d415c-03ec8c08498f92-1a343370-2073600-180bc283d42a3a%22%2C%22%24device_id%22%3A%22180bc283d415c-03ec8c08498f92-1a343370-2073600-180bc283d42a3a%22%2C%22props%22%3A%7B%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.baidu.com%2F%22%2C%22%24latest_traffic_source_type%22%3A%22%E8%87%AA%E7%84%B6%E6%90%9C%E7%B4%A2%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_utm_source%22%3A%22baidu%22%2C%22%24latest_utm_medium%22%3A%22cpc%22%2C%22%24latest_utm_campaign%22%3A%22PP0010791%22%2C%22%24latest_utm_term%22%3A%22oppo%22%7D%7D; sa_distinct_id=180bc283d415c-03ec8c08498f92-1a343370-2073600-180bc283d42a3a; cookies-tips=should_close; us=shouye; um=banner; acw_tc=2f6a1fc916524507673365861edd4328fa46d6ea10784638dfcbe06d63f70a',
		Host: 'www.opposhop.cn',
		Referer: 'https://www.opposhop.cn/cn/m/',
		s_channel: 'h5_m',
		s_version: '',
		sa_distinct_id: '180bc283d415c-03ec8c08498f92-1a343370-2073600-180bc283d42a3a',
		"Sec-Fetch-Dest": "empty",
		'Sec-Fetch-Mode': 'cors',
		'Sec-Fetch-Site': 'same-origin',
		source_type: 504,
		uc: 'direct',
		um: 'banner',
		us: 'shouye',
		'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',
		ut: 'direct',
		utm_campaign: 'direct',
		utm_medium: 'direct',
		utm_source: 'direct',
		utm_term: 'direct',
	}
})
// 2. 配置拦截器，请求的拦截器以及响应的拦截器
instance.interceptors.request.use(
	function (config) {
		Toast.loading({
			message: '加载中...',
			forbidClick: true,
			duration: 0,
		});
		// 登录之后一般返回一个 token，登录的凭证，配置在config中
		return config
	},
	function (error) {
		Toast.clear();
		return Promise.reject(error)
	}
)
instance.interceptors.response.use(
	function (response) {
		Toast.clear();
		return response.data
	},
	function (error) {
		return Promise.reject(error)
	}
)
export default instance
